package tspda

import glory.xxd.Utils
import tsCIM.ResultCode
import tsCIM.modelForInterface.Header
import tsCIM.modelForInterface.RequestModel
import tsCIM.modelForInterface.ResultModel
import tsCIM.modelForInterface.Return

class PDADefectWhyInfoRequestController {

    def commentService
    def index() {
        def result = ResultModel.getResultModel()
        try {
            def USERNAME = params.USERNAME?:""
            def EQPID = params.EQPID?:""

            def MACHINENAME = params.MACHINENAME?:""

            def body = [EQPID:EQPID,USERNAME:USERNAME]
            Header header = new Header(TRANSACTIONID:Utils.getUUID(),MESSAGENAME:"PDADefectWhyInfoRequest",MACHINENAME:MACHINENAME)
            Return aReturn = new Return()
            RequestModel requestModel = new RequestModel(header: header,body: body,aReturn: aReturn)
//            result = commentService.getJsonByTopic2Queue(requestModel,"sendmqname","returnmqname",true,responseXml)
            result = commentService.getJsonByTopic2Queue(requestModel,"jms.topic.PDA.TO.CIM","jms.queue.CIM.PDA.Send",false,false)
        }catch (Exception e){
            result.put(ResultModel.ServerErrorFlag,true)
            result.put(ResultModel.Code,ResultCode.SERVER_INTERFACE_ERROR.code)
            result.put(ResultModel.Msg,ResultCode.SERVER_INTERFACE_ERROR.msg)
            result.put(ResultModel.Data,e.getMessage())
        }finally{
            render Utils.getFormatString(result)
        }
    }

    def responseXml ="""
<MESSAGE>
<HEADER>
  <TRANSACTIONID>9dde2c51-c269-4d09-b932-649cdfc1dadb</TRANSACTIONID>
  <MESSAGENAME>PDADefectWhyInfoResponse</MESSAGENAME>
  <MACHINENAME>WM-2112</MACHINENAME>
  <WORKNO>1</WORKNO>
  <EVENTUSER>CIM</EVENTUSER>
  <EVENTTIME>2019-03-14 16:41:43.648</EVENTTIME>
</HEADER>
<BODY>
  <EQPID>DB-447</EQPID>
  <USERNAME>IE05</USERNAME>
  <DEFECTLIST>
    <PROCESSLIST>
      <PROCESSINFO>
        <PROCESSNAME>塑封</PROCESSNAME>
        <DEFECTWHYLIST>
          <DEFECT>
            <NAME>报废原因1</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
          <DEFECT>
            <NAME>报废原因2</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
        </DEFECTWHYLIST>
      </PROCESSINFO>
      <PROCESSINFO>
        <PROCESSNAME>压焊</PROCESSNAME>
        <DEFECTWHYLIST>
          <DEFECT>
            <NAME>报废原因1</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
          <DEFECT>
            <NAME>报废原因2</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
        </DEFECTWHYLIST>
      </PROCESSINFO>
      <PROCESSINFO>
        <PROCESSNAME>上芯</PROCESSNAME>
        <DEFECTWHYLIST>
          <DEFECT>
            <NAME>报废原因1</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
          <DEFECT>
            <NAME>报废原因2</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
        </DEFECTWHYLIST>
      </PROCESSINFO>
      <PROCESSINFO>
        <PROCESSNAME>划片</PROCESSNAME>
        <DEFECTWHYLIST>
          <DEFECT>
            <NAME>报废原因1</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
          <DEFECT>
            <NAME>报废原因2</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
        </DEFECTWHYLIST>
      </PROCESSINFO>
      <PROCESSINFO>
        <PROCESSNAME>减薄</PROCESSNAME>
        <DEFECTWHYLIST>
          <DEFECT>
            <NAME>报废原因1</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
          <DEFECT>
            <NAME>报废原因2</NAME>
            <COUNT>0</COUNT>
          </DEFECT>
        </DEFECTWHYLIST>
      </PROCESSINFO>
    </PROCESSLIST>
  </DEFECTLIST>
</BODY>
<RETURN>
  <RETURNCODE>0</RETURNCODE>
  <RETURNMESSAGE>返回各个工序的报废原因</RETURNMESSAGE>
</RETURN>
</MESSAGE>
"""
}

